<?php
namespace Tbf\Bundle\TbfBundle\Controller;

//use Symfony\Bundle\FrameworkBundle\Controller\Controller as BaseController;
use Symfony\Component\HttpFoundation\Response;
use Tbf\Bundle\TbfBundle\DependencyInjection\TbfContainerAware;
use Tbf\Component\Encode\EncodeUtil;

class TbfController extends TbfContainerAware
{
    protected function jsonReturn($data,$code=200)
    {
        $json_data = EncodeUtil::jsonEncode($data);

        return new Response($json_data,$code);
    }
    protected function ajkSuccess($data=null)
    {
        return $this->jsonReturn(array(
            'err'=>null,
            'data'=>$data
        ));
    }
    protected function ajkError($reason='fail!',$code=200)
    {
        return $this->jsonReturn(array(
            'err'=>$reason,
            'data'=>null
        ),$code);
    }
    /**
     * @deprecated
     */
    protected function jsonSuccess($data=null)
    {
        return $this->jsonReturn(array(
            'status'=>1,
            'info'=>'success',
            'data'=>$data
        ));
    }
    /**
     * @deprecated
     */
    protected function jsonError($reason='fail!',$code=200)
    {
        return $this->jsonReturn(array(
            'status'=>0,
            'info'=>$reason,
            'data'=>null
        ),$code);
    }
    protected function htmlMessageError($info=null,$option=array()){
        return $this->get('tbf_ajk_api.controller.html_message')->errorPage($info,$option);
    }
    protected function htmlMessageSuccess($info=null,$option=array()){
        return $this->get('tbf_ajk_api.controller.html_message')->successPage($info,$option);
    }
}
